package com.zhongyi.util;


import java.lang.reflect.InvocationTargetException;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.zhongyi.entity.Company;

/**
 * Http请求辅助工具类
 * <p>
 * 
 *
 * @author <a href="mailto:lysongfei@gmail.com">songfei</a>
 * @version 3.0, 2012-4-24
 */
public class HttpUtil {
	
	private static Logger logger = Logger.getLogger(HttpUtil.class);
	
	public static void setComapny(Company corp,HttpServletRequest request){
		try {
			BeanUtils.setProperty(corp, "corp_name", request.getParameter("p_corp_name"));
			BeanUtils.setProperty(corp, "area_id", request.getParameter("p_area_id"));
			BeanUtils.setProperty(corp, "adress", request.getParameter("p_adress"));
			BeanUtils.setProperty(corp, "origin_site", request.getParameter("p_origin_site"));
			BeanUtils.setProperty(corp, "home_page", request.getParameter("p_home_page"));
			BeanUtils.setProperty(corp, "corp_level", request.getParameter("p_corp_level"));
			BeanUtils.setProperty(corp, "corp_type", request.getParameter("p_corp_type"));
			BeanUtils.setProperty(corp, "linker", request.getParameter("p_linker"));
			BeanUtils.setProperty(corp, "keyword", request.getParameter("p_keyword"));
			BeanUtils.setProperty(corp, "remark", request.getParameter("p_remark"));
			//表单临时赋值字段
			BeanUtils.setProperty(corp, "email", request.getParameter("p_email"));
			BeanUtils.setProperty(corp, "phone", request.getParameter("p_phone"));
			BeanUtils.setProperty(corp, "mobile", request.getParameter("p_mobile"));
			BeanUtils.setProperty(corp, "fax", request.getParameter("p_fax"));
		} catch (IllegalAccessException e) {
			logger.info("", e);
		} catch (InvocationTargetException e) {
			logger.info("",e);
		}
	}
	
	public static HttpServletRequest getRequest(){
		return ServletActionContext.getRequest();
	}
	
	public static HttpServletResponse getResponse(){
		ActionContext.getContext().getSession();
		return ServletActionContext.getResponse();
	}
	
	public static HttpSession getSession(){
		return ServletActionContext.getRequest().getSession();
	}
	
	public static ServletContext getServletContext(){
		return ServletActionContext.getServletContext();
	}
}
